package com.woniuxy.carlife.carlifeuserweb.controller;


//import cn.hutool.core.util.ObjectUtil;
//import com.woniuxy.carlife.carlifecommonsweb.exception.CarlifeGlobalException;
//import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
//import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
//import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
//import com.woniuxy.carlife.carlifecommonsweb.util.JwtUtil;
//import com.woniuxy.carlife.carlifeusermodel.dto.CaryearsDto;
//import com.woniuxy.carlife.carlifeusermodel.dto.ShoppingcartDto;
//import com.woniuxy.carlife.carlifeusermodel.param.Shoppingcartparam;
//import com.woniuxy.carlife.carlifeuserweb.entity.Caryears;
//import com.woniuxy.carlife.carlifeuserweb.entity.Shoppingcart;
//import com.woniuxy.carlife.carlifeuserweb.service.ShoppingcartService;
//import com.woniuxy.carlife.carlifeuserweb.util.StatusMessageEnum;
//import io.jsonwebtoken.Claims;
//import io.swagger.annotations.*;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.annotation.Resource;
//import java.util.List;
//
///**
// * @author zjq
// * @ClassName:ShoppingcartController
// * @Description:用户购物车
// * @date 2021/4/6 20:02
// **/
//
//@Slf4j
//@RestController
//@Api(tags = "用户购物车接口信息")//用于描述接口类的相关信息，作用于类上
//@RequestMapping("/shoppingcart")
public class ShoppingcartController {
//    @Resource
//    ShoppingcartService shoppingcartService;
//

//    /*
//     * 功能描述〈用户查询购物车〉
//     * @author:zjq
//     * @param:
//     * @return:
//     * @Date 2021/4/12 11:54
//     * @throws
//     */
//    //@ApiOperation用于描述接口方法，作用于方法上
//    @ApiOperation(value = "用户查询购物车,解析token")
//    //@ApiResponses用于描述响应状态信息
//
//    @GetMapping("/ordinary/findShoppingcartByUserId")
//    public Result findShoppingcartByUserId() {
//        ServletRequestAttributes sra =
//                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String token = sra.getRequest().getHeader("token");
//        JwtUtil jwtUtil = new JwtUtil();
//        Claims claims = jwtUtil.parseTokenOrdinary(token);
//        if (claims == null) {
//
//            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
//        }
//        Object o = claims.get("token");
//        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
//        List<Shoppingcart> shoppingcartByUserId = shoppingcartService.findShoppingcartByUserId(tokenUserId);
//
//
//        if (ObjectUtil.isNull(shoppingcartByUserId)) {
//            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString());
//        }
//
//        List<ShoppingcartDto> shoppingcartlist = CopyUtil.getList(shoppingcartByUserId, ShoppingcartDto.class);
//
//        return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), shoppingcartlist);
//    }
//
//    /*
//     * 功能描述〈用户新增购物车〉
//     * @author:zjq
//     * @param:
//     * @return:
//     * @Date 2021/4/13 4:53
//     * @throws
//     */
//
//    //@ApiOperation用于描述接口方法，作用于方法上
//    @ApiOperation(value = "用户新增购物车")
//    //@ApiResponses用于描述响应状态信息
//
//    @PostMapping("/ordinary/addShoppingcartByUserId")
//
//    public Result addShoppingcartByUserId(@ApiParam Shoppingcartparam Shoppingcartparam) {
//        ServletRequestAttributes sra =
//                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String token = sra.getRequest().getHeader("token");
//        JwtUtil jwtUtil = new JwtUtil();
//        Claims claims = jwtUtil.parseTokenOrdinary(token);
//        if (claims == null) {
//
//            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
//        }
//        Object o = claims.get("token");
//        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
//        Shoppingcart one = CopyUtil.getOne(Shoppingcartparam, Shoppingcart.class);
//        one.setUserId(tokenUserId);
//        log.info("准备执行新增购物车");
//        boolean b = shoppingcartService.addShoppingcartByUserId(one);
//        log.info("执行新增购物车完毕");
//        return b == true ? new Result(true, StatusCode.ADDED_SUCCESSFULLY, StatusMessageEnum.ADDED_SUCCESSFULLY.toString())
//                : new Result(true, StatusCode.ADD_FAILED, StatusMessageEnum.ADD_FAILED.toString());
//    }
//
//    /*
//     * 功能描述〈用户删除购物车〉
//     * @author:zjq
//     * @param:
//     * @return:
//     * @Date 2021/4/13 4:54
//     * @throws
//     */
//
//
//    //@ApiOperation用于描述接口方法，作用于方法上
//    @ApiOperation(value = "用户删除购物车")
//    //@ApiResponses用于描述响应状态信息
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "shoppingcartId", value = "购物车id"
//                    , example = "1", required = true, paramType = "query", dataType = "String")
//    })
//    @PostMapping("/ordinary/deleteShoppingcartByShoppingcartId")
//    public Result deleteShoppingcartByShoppingcartId(Integer shoppingcartId) {
//        if (shoppingcartId == null && shoppingcartId == 0) {
//            new Result(true, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
//        }
//        ServletRequestAttributes sra =
//                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String token = sra.getRequest().getHeader("token");
//        JwtUtil jwtUtil = new JwtUtil();
//        Claims claims = jwtUtil.parseTokenOrdinary(token);
//        if (claims == null) {
//
//            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
//        }
//        Object o = claims.get("token");
//        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
//        log.info("开始执行删除购物车");
//        boolean b = shoppingcartService.deleteShoppingcartByShoppingcartId(shoppingcartId,tokenUserId);
//        log.info("开始执行删除购物车完毕");
//        return b == true ? new Result(true, StatusCode.SUCCESSFULLY_DELETED, StatusMessageEnum.SUCCESSFULLY_DELETED.toString())
//                : new Result(true, StatusCode.FAILED_TO_DELETE, StatusMessageEnum.FAILED_TO_DELETE.toString());
//    }


}

